<?php
/**
 * 榜单详情推荐 wiki列表
 */

use Biz\service\wikiRanking\Ranking;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\service\statSign\Basic as statSign;
use Doraemon\tools\ActionLog;
use Doraemon\tools\BlockType;

class TopWikiListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;
    const IS_LOG_EXPOSE = 1;

    public function main()
    {
        $params = $this->getRequest()->getPost();
        $p['ranking_id'] = $params['ranking_id'] ?? 0;
        $p['per_page'] = $params['per_page'] ?? 20;
        $p['current_page'] = $params['current_page'] ?? 1;
        $p['uid'] = $this->uid;
        $type = $params['type'] ?: 1; //1：热度榜 2：口碑榜


        if (!$p['ranking_id']) {
            throw new \Exception('ranking_id不能为空');
        }
        $data = [];
        if ($type == 1) {
            $act_from = 'hot_ranking ';
            $data = Ranking::getTopHotWikiList($p);
        } elseif ($type == 2) {
            $act_from = 'brand_ranking ';
            $data = Ranking::getTopPublicPraiseWikiList($p);
        }


        if ($data['list']) {
            //埋点
            $i = 0;
            $pos = ($type == 1) ? 'location_2' : 'location_4';
            $tab = ($type == 1) ? 'hot' : 'publicpraise';
            foreach ($data['list'] as $key => $v) {
                $data['list'][$key]['statSign'] = statSign::genStatSign(statSign::MODULE_BANGDAN_DETAIL_LIST, [
                    statSign::EXTEND_KEY_OBJ_ID => $v['id'],
                    statSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_WIKI,
                    statSign::EXTEND_KEY_INDEX => $i,
                    statSign::EXTEND_KEY_POS => $pos,
                    statSign::EXTEND_KEY_OBJ_UID => $v['brand_id'],
                    statSign::EXTEND_KEY_RELATE_OBJ_ID => $p['ranking_id'],
                    statSign::EXTEND_KEY_RELATE_OBJ_TYPE => BlockType::TYPE_RANKING,
                ], [
                    'tab' => $tab
                ]);
                $i++;
            }
        }
        ActionLog::log($this->uid, $params, ActionLog::TOP_WIKI_LIST);
        $this->setSuccess($data);
    }

}